class code3 {
    //栈模拟：一个栈存数字int  一个（栈）op存字符
    //分类讨论
    //1.遇到op：直接更新
    //2.遇到数字:找到tmp
    //然后分op进行操作:
    //+:直接入栈
    //-:相反数入栈
    //*:与栈顶元素*入栈
    ///：同上
    public int calculate(String s) {
        Stack<Integer> st = new Stack<>();
        char op = '+';
        int ret = 0;
        //遍历s
        int i = 0;
        char[] ss = s.toCharArray();
        while(i<s.length()) {
            if(ss[i]>='0'&&ss[i]<='9') {
                int tmp = 0;
                while(i<ss.length && ss[i]>='0'&&ss[i]<='9') {
                    tmp = 10*tmp + (ss[i++]-'0');
                }
                if(op=='+') st.push(tmp);
                else if(op=='-') st.push(-tmp);
                else if(op=='*') st.push(st.pop()*tmp);
                else st.push(st.pop()/tmp);
            } else if(ss[i]==' '){
                i++;
            } else {
                op = ss[i++];
            }
        }
        while(!st.isEmpty()) {
            ret += st.pop();
        }
        return ret;
    }
}